home *** CD-ROM | disk | FTP | other *** search
- Path: news.mindspring.com!usenet
- From: rudd@mindspring.com (Justin Rudd)
- Newsgroups: comp.lang.c++
- Subject: Re: C++ newbie asks for help
- Date: Fri, 15 Mar 1996 03:49:21 GMT
- Organization: MindSpring Enterprises
- Message-ID: <4iapek$med@B1FF.mindspring.com>
- References: <31488AC8.1557@cco.caltech.edu>
- Reply-To: rudd@mindspring.com
- NNTP-Posting-Host: rudd.mindspring.com
- X-Newsreader: Forte Free Agent v0.55
-
- This is a very common problem with 4.0 console apps. The problem is
- you aren't filling the internal buffer with enough characters. What
- this basically means is...after it does the cout << "starting\a\n";
- This doesn't fill the buffer enough to be dumped. Its screwy but easy
- to fix...just add this line right after any cout or ostream operation.
-
- cout.flush();
-
- This will flush everything in the buffer out to the screen. The
- reason it has a buffer is because in 95 and NT it is not true DOS but
- a DOS session so they allocate a buffer for text and wait till its
- filled before dumping it. Now don't think this is just because it is
- windows. I've had this problem before with DOS and OS/2 :-)
-
- >#include <iostream.h>
- >#include <time.h> // describes clock() function, clock_t type
- >int main(void)
- >{
- > cout << "Enter the delay time, in seconds: ";
- > float secs; cin >> secs;
- > clock_t delay = secs * CLOCKS_PER_SEC;
- > // convert to clock ticks
- > cout << "starting\a\n";
- cout.flush();
- ^^^^^^^^^^
- > clock_t start = clock();
- > while (clock() - start < delay )
- > // wait until time elapses
- > ;
- > cout << "done \a\n";
- cout.flush();
- ^^^^^^^^^
- > return 0;
- >}
-
- Same as the above...just insert cout.flush() after each line.
-
- >Program #2
- >// textin3.cpp -- reading chars to end of file
- >#include <iostream.h>
- >int main(void)
- >{
- > char ch;
- > int count = 0;
-
- > while (cin.get(ch)) // cin.get(ch) is 0 on EOF
- > {
- > cout << ch;
- > count++;
- > }
- > cout << count << " characters read\n";
- > return 0;
- >}
-
- Hope this helps :-)
-
- Justin
-
- P.S.( I say again....I have had this problem on DOS and OS/2 )
-
-